package com.ubst.smartad.impl.admin.log;

import java.sql.*;
import java.util.*;
import java.io.*;

import com.ubst.smartad.common.TimeUtil;
import com.ubst.smartad.logger.Debug;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Vector;

public class LogMngImpl {
	
	Connection con = null;
	private String serverName;
	private Debug debug;
	//private FileHostEnv fhostEnv;


    /** 
     * 생성자
     *   
     *   
    */ 
	public LogMngImpl(Connection con, String serverName, String log_level) {
		this.con = con;
		this.serverName = serverName;
		this.debug = new Debug("TestMngImpl", log_level);
		//this.fhostEnv = FileHostEnv.getInstance(serverName);

	}
	
	/**
	 *  @author Kswany
	 * 	Log(로그) - Network(네트워크 접근제어) jqGrid List 가져오기
	 * 
	 *  searchStr: 검색조건
	 *  orderBy: sort조건
	 *  prev_page: first limit 
	 *  next_page: last limit
	 *  
	 * **/
	public List getJqgridList(String searchStr, String orderBy, int prev_page, int next_page) 
//			throws SQLException{
			throws Exception{
		PreparedStatement pstmt=null;
		ResultSet rs = null;

		HashMap log_data_map = null;
		List log_datas = new ArrayList();
		
		try{
		/*
		 *  DB value 값세팅 구현 로직 들어갈 부분
		 */
		// 가상데이터
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "window");
		log_data_map.put("calender", "2013-08-21");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "실패");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "test01");
		log_data_map.put("ip_addr", "121.118.1.2");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "solaris");
		log_data_map.put("calender", "2012-11-03");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "test02");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);
		
		log_data_map = new HashMap();
		log_data_map.put("system_name", "redhat");
		log_data_map.put("calender", "2013-07-06");
		log_data_map.put("type", "시스템 등록");
		log_data_map.put("work", "계정등록");
		log_data_map.put("result", "성공");
		log_data_map.put("important", "정보");
		log_data_map.put("worker", "adadmin");
		log_data_map.put("ip_addr", "192.168.1.1");
		log_datas.add(log_data_map);

	//	}catch (SQLException e){
		}catch (Exception e){
			throw e;
		}finally{
	//		if ( rs != null) try{rs.close();}catch(SQLException ee){}
	//		if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
	
		return log_datas;
	}
	
		
	/**
	 * @author : Kswany 
	 * Log(로그) - Network(네트워크 접근제어) Info 가져오기 View
	 *	Primary key: system_name(가상설정)
	 */
	public HashMap getLogInfo(String system_name) 
//			throws SQLException {
			throws Exception{

		PreparedStatement pstmt=null;
		ResultSet rs = null;

		HashMap log_info_map = new HashMap();

		try {
			/*
			 *  DB value 값세팅 구현 로직 들어갈 부분
			 */
			// 가상데이터
			log_info_map.put("system_name", "redhat_TEST");
			log_info_map.put("calender", "2013-07-06");
			log_info_map.put("type", "시스템 등록");
			log_info_map.put("work", "계정등록");
			log_info_map.put("result", "성공");
			log_info_map.put("important", "정보");
			log_info_map.put("worker", "adadmin");
			log_info_map.put("ip_addr", "192.168.1.1");
			
		}catch (Exception e){
			throw e;
		}finally{
//			if ( rs != null) try{rs.close();}catch(SQLException ee){}
//			if ( pstmt != null) try{pstmt.close();}catch(SQLException ee){}
		}
		
		
		return log_info_map;
	}
}
